package com.huluobo.a2208kotlindouyindemo.utils

import android.content.Context
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.youth.banner.Banner
import com.youth.banner.loader.ImageLoader

/**
 *  Created by LC on 2024/12/31.
 */
object BindAdapter {
    @BindingAdapter("bindImgUrl")
    @JvmStatic
    fun loadImage(imageView: ImageView, url: String?) {
        if (url != null) {
//            ImageUtils.loadImage(imageView.context, url, imageView)
            Glide.with(imageView.context).load(url).into(imageView)
        }
    }

    @BindingAdapter("bindBanner")
    @JvmStatic
    fun loadBanner(banner: Banner, images: List<String>?) {
        if (!images.isNullOrEmpty()) {
            banner.setImageLoader(object : ImageLoader() {
                override fun displayImage(context: Context?, path: Any?, imageView: ImageView?) {
                    if (context != null && imageView != null) {
                        ImageUtils.loadImage(context, path.toString(), imageView)
                    }
                }
            })
            banner.update(images)
        }
    }
}